<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-09-24 10:54:00
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" inventory
-->
<template>
  <sc-VxeTable ref="xGrid" :gridEvts="gridEvents" :tablecode="'finance_acceptance_index'"
    :url="api.finance.acceptance.list">
  </sc-VxeTable>

  <SaveDialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></SaveDialog>
  <ScheduleDialog v-if="dialog.schedule" ref="scheduleDialog" @success="handleSuccess" @closed="dialog.schedule = false">
  </ScheduleDialog>
  <DebtDialog v-if="dialog.debt" ref="debtDialog" @success="handleSuccess" @closed="dialog.debt = false">
  </DebtDialog>
</template>
<script>
export default {
  name: "finance_generalLedger_acceptance",
};
</script>
<script setup>
// import { useRouter } from "vue-router";
import { ref, nextTick } from "vue";
// , onMounted, reactive, ref
// const router = useRouter();
import SaveDialog from "./save";
import DebtDialog from "./debt"
import ScheduleDialog from "./schedule";

import api from "@/api";
const dialog = ref({
  save: false,
  schedule: false,
  debt: false
});

const xGrid = ref({});
const saveDialog = ref({});
const scheduleDialog = ref({});
const debtDialog = ref({});
const handleSuccess = () => {
  xGrid.value.refresh();
};

const gridEvents = {
  cellDblclick: function ({ row }) {
    gridEvents.edit(row);
  },
  add: function () {
    dialog.value.save = true;
    nextTick(() => {
      saveDialog.value.open();
    });
  },
  editschedule: function ({ button }) {
    dialog.value.schedule = true;
    nextTick(() => {
      scheduleDialog.value.setData(button.selectRecords);
      scheduleDialog.value.open("edit");
    });
  },
  debtor: function ({ button }) {
    dialog.value.debt = true;
    nextTick(() => {
      debtDialog.value.setData(button.selectRecords[0]);
      debtDialog.value.open("edit");
    });
  },
  edit: function (data) {
    dialog.value.save = true;
    if (typeof data.$grid !== "undefined") {
      data = data.$grid.getCheckboxRecords()[0];
    }
    nextTick(() => {
      saveDialog.value.setData(data);
      saveDialog.value.open("edit");
    });
  },
};
</script>
